package top.eggcode.system.modules.user.store;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import top.eggcode.system.modules.user.model.AccountRoleEntity;

import java.util.List;

/**
 * Title:
 * Description: TODO
 * Date: 2021/8/7 15:08
 *
 * @author JiaQi Ding
 * @version 1.0
 */
public interface AccountRoleRepository extends JpaRepository<AccountRoleEntity, String> {


    /**
     * 查找角色id列表
     *
     * @param accountId 账户id
     * @return
     */
    List<AccountRoleEntity> findByAccountId(String accountId);

    /**
     * 删除角色
     *
     * @param accountId 帐户
     */
    @Modifying
    @Query("delete from AccountRoleEntity relation where relation.accountId = :accountId")
    void batchDeleteByAccount(@Param("accountId") String accountId);

    Long deleteByAccountId(String accountId);

}
